/**
 * Created by sita-st on 2017/6/26.
 */

//验证手机号
function isMobile(mobile) {
    var reg = /^[1][3578][0-9]{9}$/;
    return reg.test(mobile);
}

//验证邮箱
function isEmail(str) {
    var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
    return reg.test(str);
}


//使搜索栏居中
function middle() {
    var len = 0;
    var divs = $(".page-header .form-group").parent(
        ":visible"
    );
    for (var i = 0; i < divs.length; i++) {
        var div = divs.eq(i);
        if (i == divs.length - 1) {
            len += parseInt(div.css("margin-left"));
            len += parseInt(div.css("width"));
            var w = 0;
            for (var j = 0; j < div.children().eq(0).children().length; j++) {
                var btn = div.children().eq(0).children().eq(j);
                if (j == div.children().eq(0).children().length - 1) {
                    w += parseInt(btn.css("margin-left"));
                    w += parseInt(btn.css("width"));
                    w += div.children().eq(0).children().length * 3;
                    w += parseInt(div.css("padding-left")) * 2;
                } else {
                    w += parseInt(btn.css("margin-left"));
                    w += parseInt(btn.css("width"));
                    w += parseInt(btn.css("margin-right"));
                }
            }
            div.css("width", w);
        } else {
            len += parseInt(div.css("margin-left"));
            len += parseInt(div.css("width"));
            len += parseInt(div.css("margin-right"));
        }
    }
    var mgl = (parseInt($(".page-header").css("width")) - len) / 2;
    // divs.eq(0).css("margin-left",mgl+"px");
    if (mgl > 0 && len<800) {
        divs.css("position", "relative").animate({
                left: mgl + 40 + "px"
            }, 500
            , function () {
                divs.animate({
                    left: mgl - 20 + "px"
                }, 100, function () {
                    divs.animate({
                        left: mgl + "px"
                    }, 200)
                })
            }
        );
    }else if(mgl > 0 && len>=800){
        divs.css("position", "relative").animate({
                left: mgl + 20 + "px"
            }, 300
            , function () {
                divs.animate({
                    left: mgl - 10 + "px"
                }, 50, function () {
                    divs.animate({
                        left: mgl + "px"
                    }, 100)
                })
            }
        );
    }
    return;
}

